const path = require('path');
const express = require('express');
const cors = require('cors');
const morgan = require('morgan');
const planetsRouter = require('./routes/planets/planets.router');
const launchesRouter = require('./routes/launches/launches.router');
const app = express();
app.use(launchesRouter);
app.use(cors({
 origin: '<http://localhost:3000>',
}));
app.use(morgan('combined'));
// 使⽤ express 内置的中间件解析 JSON 格式的请求体
app.use(express.json());
// 使⽤ express static 中间件处理静态资源
app.use(express.static(path.join(__dirname, '..', 'public')));
// 使⽤ planetsRouter 处理 /planets 路由
app.use(planetsRouter);
// 处理根路由的 GET 请求，加载 public/index.html ⽂件
app.use('/planets', planetsRouter);
app.use('/launches', launchesRouter);
app.get('/*', (req, res) => {
 res.sendFile(path.join(__dirname, '..', 'public', 'index.html'));
});
module.exports = app;